import logging

from redis import StrictRedis


class Config(object):
    """项目的配置"""
    DEBUG = True
    SECRET_KEY = "CN9/P1wNUbNS/YFhTn9PS9xrrMwGNQyIyPOLR4r8vpLdwdpRRXUOE7SjJ42L9CrE"

    # 为数据库添加配置
    SQLALCHEMY_DATABASE_URI = "mysql+pymysql://root:mysql@127.0.0.1:3306/info02"
    SQLALCHEMY_TRACK_MODIFICATIONS = False

    # redis 的配置
    REDIS_HOST = "127.0.0.1"
    REDIS_PORT = 6379

    # session 保存配置
    SESSION_TYPE = "redis"
    # 开启session签名
    SESSION_USE_SIGNER = True
    # TODO 指定session保存的 redis  啥意思？和"初始化 redis 存储对象"有啥关系？
    SESSION_REDIS = StrictRedis(host=REDIS_HOST, port=REDIS_PORT)
    # 设置需要过期
    SESSION_PERMANENT = False
    # 设置过期时间
    permanent_session_lifetime = 86400 * 2

    # 设置日志的等级
    LOG_LEVEL = logging.DEBUG


class DevelopmentConfig(Config):
    """开发环境下的配置"""
    DEBUG = True


class ProductionConfig(Config):
    """生产环境的配置"""
    DEBUG = False
    LOG_LEVEL = logging.WARNING


class TestingConfig(Config):
    """测试环境的配置"""
    DEBUG = True
    TESTING = True


config = {
    # "development": "DevelopmentConfig",
    # "production": "ProducionConfig",
    # "testing": "TestingConfig"
    "development": DevelopmentConfig,
    "production": ProductionConfig,
    "testing": TestingConfig
}